package com.robot.common.core.tool;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.robot.common.core.domain.Query;
import freemarker.ext.servlet.IncludePage;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.core.parameters.P;

/**
 * @Description:TODO
 * @author:qzg
 * @Date:2021-01-30 10:09
 */
public class PageTransform {

    public static <T> IPage<T> getPage(Query query){
        Page<T> page = new Page(query.getCurrent(),query.getSize());
        String ascs = filter(query.getAscs());
        if(ascs != null && !ascs.equals("")){
            String [] as = query.getAscs().split(",");
            page.setAscs(ListUtil.toList(as));
        }
        String descs = filter(query.getDescs());
        if(descs != null && !descs.equals("")){
            String [] des = query.getDescs().split(",");
            page.setDescs(ListUtil.toList(des));
        }
        return page;
    }



    public static String filter(String param) {
        return param == null ? null : param.replaceAll("(?i)'|%|--|insert|delete|select|count|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql", "");
    }
}
